package com.hqyj.controller;


import com.hqyj.pojo.TbRepair;
import com.hqyj.service.TbRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 维修表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-repair")
public class TbRepairController {
    @Autowired
    TbRepairService tbRepairService;

    /**
     * 新增
     * http://localhost:8080/tb-repair/add
     * {"communityName":"蓝雾苑","communityId":"1","buildingName":"27舍","buildingId":"6","ownerName":"张三",
     * "ownerId":"1","deviceName":"空调","deviceId":"1","description":"空调不制冷",
     * "createTime":"2021-09-27 19:20:47","updateTime":"2021-09-27 19:20:47","status":"0"}
     *
     * @param tbRepair
     * @return
     */
    @PostMapping(value = "/add", consumes = "application/json")
    public HashMap<String, Object> add(@RequestBody TbRepair tbRepair) {
        return tbRepairService.add(tbRepair);
    }

    /**
     * 修改
     * http://localhost:8080/tb-repair/update
     * {"id":"1","status":"1"}
     *
     * @param tbRepair
     * @return
     */
    @PutMapping(value = "/update", consumes = "application/json")
    public HashMap<String, Object> update(@RequestBody TbRepair tbRepair) {
        return tbRepairService.update(tbRepair);
    }

    /**
     * 删除
     * http://localhost:8080/tb-repair/del/?
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public HashMap<String, Object> del(@PathVariable Integer id) {
        return tbRepairService.del(id);
    }

    /**
     * 查询
     * http://localhost:8080/tb-repair/list?page=1&row=2
     *
     * @param tbRepair
     * @return
     */
    @GetMapping("/list")
    public HashMap<String, Object> list(TbRepair tbRepair) {
        return tbRepairService.list(tbRepair);
    }

    /**
     * 通过报修人姓名查询
     * http://localhost:8080/tb-repair/repairOwnerName
     *
     * @param ownerName
     * @return
     */
    @GetMapping("/repairOwnerName")
    public HashMap<String, Object> repairOwnerName(String ownerName) {
        return tbRepairService.repairOwnerNameList(ownerName);
    }
}

